package club.pinea.session;

import club.pinea.proto.UserProto;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.util.Assert;

import java.util.List;

/**
 * 客户端保存用户信息
 */
public class ClientPlayer {

    private static ChannelHandlerContext context;

    /**
     * 服务端返回的用户信息
     */
    private static UserProto.User userInfo;

    /**
     * 大厅地址
     */
    private static String lobbyHost;
    /**
     * 大厅端口
     */
    private static Integer lobbyPort;

    /**
     * 当前倍率
     */
    private static Integer multiplyPower;

    /**
     * 当前所在的房间信息
     */
    private static Integer roomId;

    /**
     * 最大分数
     */
    private static Integer maxScore;
    /**
     * 最小分数
     */
    private static Integer minScore;
    /**
     * 当前奖池份数
     */
    private static List<Integer> bonus;

    /**
     * 比倍次数
     */
    private static int doubleTime = 0;
    /**
     * 比倍倍数
     */
    public static int[] doublePower = new int[]{5, 10, 20};

    /**
     * 设置user
     *
     * @param response
     */
    public static void setInfo(UserProto.LoginResponse response) {
        ClientPlayer.userInfo = response.getUser();
        ClientPlayer.lobbyHost = response.getLobbyHost();
        ClientPlayer.lobbyPort = response.getLobbyPort();

    }

    /**
     * 退出时清除所有信息
     */
    public static void clear() {
        ClientPlayer.userInfo = null;
        ClientPlayer.context = null;
    }

    /**
     * 获取大厅端口
     *
     * @return
     */
    public static Integer getLobbyPort() {
        Assert.notNull(lobbyPort, "lobbyPort is not init....");
        return lobbyPort;
    }

    /**
     * 获取大厅地址
     *
     * @return
     */
    public static String getLobbyHost() {
        Assert.notNull(lobbyHost, "lobbyHost is not init....");
        return lobbyHost;
    }

    public static Integer getUserId() {
        return userInfo.getId();
    }

    public static String getToken() {
        return userInfo.getToken();
    }

    public static UserProto.User getUserInfo() {
        return userInfo;
    }

    public static void setUserInfo(UserProto.User userInfo) {
        ClientPlayer.userInfo = userInfo;
    }

    public static void setContext(ChannelHandlerContext context) {
        ClientPlayer.context = context;
    }

    public static ChannelHandlerContext getContext() {
        return context;
    }

    public static Integer getMultiplyPower() {
        return multiplyPower;
    }

    public static void setMultiplyPower(Integer multiplyPower) {
        ClientPlayer.multiplyPower = multiplyPower;
    }

    public static Integer getRoomId() {
        return roomId;
    }

    public static void setRoomId(Integer roomId) {
        ClientPlayer.roomId = roomId;
    }

    public static Integer getMaxScore() {
        return maxScore;
    }

    public static void setMaxScore(Integer maxScore) {
        ClientPlayer.maxScore = maxScore;
    }

    public static Integer getMinScore() {
        return minScore;
    }

    public static void setMinScore(Integer minScore) {
        ClientPlayer.minScore = minScore;
    }

    public static List<Integer> getBonus() {
        return bonus;
    }

    public static void setBonus(List<Integer> bonus) {
        ClientPlayer.bonus = bonus;
    }

    public static int getDoubleTime() {
        return doubleTime;
    }

    public static void setDoubleTime(int doubleTime) {
        ClientPlayer.doubleTime = doubleTime;
    }
}
